{#
Copyright (c) 2020 Andy Zhou
MIT License
#}
{% extends 'base.html' %}
{% from 'macros.html' import post_actions with context %}
{% from 'bootstrap/form.html' import render_form %}
{% block title %} Post - {{ post.title }} {% endblock %}
{% block page_content %}
    <div class="row">
        <div class="col-lg-8" style="font-size: large">
            <div class="page-header">
                <h1>
                    {{ post.title }}
                </h1>
                <small>
                    {{ _('Date:') }} {{ moment(post.timestamp).format('LL') }}<br>
                    {{ _('Author:') }}
                    <a href="{{ post.author.profile_url() }}" class="profile-popover" data-href="{{ url_for('ajax.get_profile', user_id=post.author.id) }}">
                        {{ post.author.name }}
                    </a>
                </small>
            </div><br>
            {{ post.content | safe }}
            {{ post_actions(post, show_collectors=True) }}
            <div class="comments" id="comments">
                <h3>{{ comments|length }} {{ ngettext('Comment', 'Comments', __num=comments|length) }}
                    <small>
                        <a href="{{ url_for('.full_post', slug=post.slug, page=pagination.pages or 1) }}#comments">
                            {{ _('latest') }}
                        </a>
                    </small>
                </h3>
                {{ render_form(form) }}
                {% if comments %}
                <ul class="list-group">
                    {% for comment in comments %}
                        <li class="list-group-item list-group-item-action flex-column">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">
                                    <a href="{{ comment.author.profile_url() }}" target="_blank">
                                        {{ comment.author.name }}
                                    </a>
                                </h5>
                                {% if comment.author.is_administrator() %}
                                    <span class="badge badge-danger">{{ _('Admin') }}</span>
                                {% endif %}
                                {% if comment.author == post.author %}
                                    <span class="badge badge-primary">{{ _('Author') }}</span>
                                {% endif %}
                                <small data-toggle="tooltip" data-placement="top" data-delag="500"
                                    data-timestamp="{{ comment.timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') }}">
                                    {{ moment(comment.timestamp).fromNow() }}
                                </small>
                            </div>
                            {% if comment.replied %}
                                <p class="alert alert-dark reply-body">
                                    {{ comment.replied.author.name }}:<br>
                                    {{ comment.replied.body }}
                                </p>
                            {% endif %}
                            <p class="mb-1">{{ comment.body }}</p>
                            <div class="float-right">
                                {% if current_user.is_administrator() or current_user == comment.author %}
                                    <form class="inline" method="POST" action="{{ url_for('main.delete_comment', comment_id=comment.id) }}"
                                        style="display: inline !important">
                                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                                        <button class="btn btn-sm btn-danger" onclick="return confirm('Are you sure?');">
                                            {{ _('DELETE') }}
                                        </button>
                                    </form>
                                {% endif %}
                                <a class="btn btn-light btn-sm" href="{{ url_for('main.reply_comment', comment_id=comment.id) }}">
                                    {{ _('Reply') }}
                                </a>
                            <div>
                        </li>
                        {% endfor %}
                    </ul>
                    {% if request.args.get('reply') %}
                        <div class="alert alert-dark" id="reply-comment-form">
                            Reply to <b>{{ request.args.get('author') }}</b>:
                            <a class="float-right btn btn-light btn-sm" href="{{ post.url() }}">
                                Cancel
                            </a>
                            {{ render_form(form) }}
                        </div>
                    {% endif %}
                {% else %}
                No comments yet.
                {% endif %}
            </div>
        </div>
        {% include 'main/_sidebar.html' %}
    </div>
{% endblock page_content %}
